using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace SurveyHost.Core.DAL
{
    /// <summary>
    /// Controller class for HostConfiguration
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class HostConfigurationController
    {
        // Preload our schema..
        HostConfiguration thisSchemaLoad = new HostConfiguration();
        private string userName = string.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}

					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}

				}

				return userName;
            }

        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public HostConfigurationCollection FetchAll()
        {
            HostConfigurationCollection coll = new HostConfigurationCollection();
            Query qry = new Query(HostConfiguration.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public HostConfigurationCollection FetchByID(object HostName)
        {
            HostConfigurationCollection coll = new HostConfigurationCollection().Where("HostName", HostName).Load();
            return coll;
        }

		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public HostConfigurationCollection FetchByQuery(Query qry)
        {
            HostConfigurationCollection coll = new HostConfigurationCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object HostName)
        {
            return (HostConfiguration.Delete(HostName) == 1);
        }

        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object HostName)
        {
            return (HostConfiguration.Destroy(HostName) == 1);
        }

        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(string HostName,string SurveyName,string AdministratorName,string InvitationEmail,string CompletionEmail,string AdministratorPublicEmail,string AdministratorPrivateEmail,bool ScreenApplicant,string SMTPHost,int? SMTPPort,string SMTPLoginName,string SMTPLoginPassword,bool SMTPUseSSL)
	    {
		    HostConfiguration item = new HostConfiguration();
		    
            item.HostName = HostName;
            
            item.SurveyName = SurveyName;
            
            item.AdministratorName = AdministratorName;
            
            item.InvitationEmail = InvitationEmail;
            
            item.CompletionEmail = CompletionEmail;
            
            item.AdministratorPublicEmail = AdministratorPublicEmail;
            
            item.AdministratorPrivateEmail = AdministratorPrivateEmail;
            
            item.ScreenApplicant = ScreenApplicant;
            
            item.SMTPHost = SMTPHost;
            
            item.SMTPPort = SMTPPort;
            
            item.SMTPLoginName = SMTPLoginName;
            
            item.SMTPLoginPassword = SMTPLoginPassword;
            
            item.SMTPUseSSL = SMTPUseSSL;
            
	    
		    item.Save(UserName);
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(string HostName,string SurveyName,string AdministratorName,string InvitationEmail,string CompletionEmail,string AdministratorPublicEmail,string AdministratorPrivateEmail,bool ScreenApplicant,string SMTPHost,int? SMTPPort,string SMTPLoginName,string SMTPLoginPassword,bool SMTPUseSSL)
	    {
		    HostConfiguration item = new HostConfiguration();
		    
				item.HostName = HostName;
				
				item.SurveyName = SurveyName;
				
				item.AdministratorName = AdministratorName;
				
				item.InvitationEmail = InvitationEmail;
				
				item.CompletionEmail = CompletionEmail;
				
				item.AdministratorPublicEmail = AdministratorPublicEmail;
				
				item.AdministratorPrivateEmail = AdministratorPrivateEmail;
				
				item.ScreenApplicant = ScreenApplicant;
				
				item.SMTPHost = SMTPHost;
				
				item.SMTPPort = SMTPPort;
				
				item.SMTPLoginName = SMTPLoginName;
				
				item.SMTPLoginPassword = SMTPLoginPassword;
				
				item.SMTPUseSSL = SMTPUseSSL;
				
		    item.MarkOld();
		    item.Save(UserName);
	    }

    }

}

